load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//build:STRINGER.bzl", "stringer")

go_library(
    name = "pgdate",
    srcs = [
        "field_extract.go",
        "fields.go",
        "math.go",
        "parsing.go",
        "pgdate.go",
        "setters.go",
        "zone_cache.go",
        ":gen-field-stringer",  # keep
    ],
    embed = [":pgdate_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/util/timeutil/pgdate",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/util/arith",
        "//pkg/util/errorutil/unimplemented",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_redact//:redact",
    ],
)

go_test(
    name = "pgdate_test",
    size = "small",
    srcs = [
        "field_extract_test.go",
        "fields_test.go",
        "parsing_test.go",
        "pgdate_test.go",
    ],
    embed = [":pgdate"],
    deps = [
        "//pkg/util/timeutil",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_lib_pq//:pq",
        "@com_github_stretchr_testify//require",
    ],
)

stringer(
    name = "gen-field-stringer",
    src = "fields.go",
    typ = "field",
)

proto_library(
    name = "pgdate_proto",
    srcs = ["pgdate.proto"],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
)

go_proto_library(
    name = "pgdate_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/util/timeutil/pgdate",
    proto = ":pgdate_proto",
    visibility = ["//visibility:public"],
)
